<!DOCTYPE html>
<html>
<head>
<div th:include="base-libs :: base-libs" />
<title>服务记录</title>

<meta name="keywords" content="keyword1,keyword2,keyword3">
<meta name="description" content="this is my page">
<meta name="content-type" content="text/html; charset=UTF-8">

<style>
	.laydate-icon{
		height:30px;
		line-height:30px;
		border:1px solid #B6B6B6;
	}
	.spanBtn{
		font-weight: bold;
		color: blue;
		cursor:pointer;
	}
	.tabs-wrap>.tabs>li>a{
		border-left:1px solid #438EB9!important;
		border-right:1px solid #438EB9!important;
		border-top:1px solid #438EB9!important;
	}
	.datagrid-row-selected {
		background: #FFE4A5 !important;
		color: #000000;
	}
	/*浮雕字体css*/
	.fdztCss{
		text-shadow: 1px 1px 0 rgba(255, 255, 255, .7);
		color:#ccc;
	}
</style>

<script th:inline="javascript">
	var tdxxArr = [[${tdxxArr}]];
</script>
<script>
	$(function(){
    	initView();
    	initData();
    	$("#btnQuery").trigger("click");
    })
    	
    function initView() {
		$('#tabs').tabs({
			border: true,
		    fit: true,
		    tabWidth: "160",
			onSelect: function(title,index){
				var nowSelectTab = $(this).tabs('getTab',index); //获取到当前激活的tab
				var tableId = nowSelectTab.find("table").eq(1).attr("id");
				if(!StringUtils.isEmpty(tableId)){
					initTableMethod[tableId](); //初始化table
				}
				if(index==0){
					enterToQuery(wdFwxQueryHandler);
				}else{
					enterToQuery(allFwxQueryHandler);
				}
			}
		})
		
		initTableMethod.wdFwxTable();
		enterToQuery(wdFwxQueryHandler);
		$("body").css("visibility","visible");
	}
	
	function initData(){
		//团队下拉框
		/*var $TDID = $("[name=TDIDS]");
		$.each(tdxxArr, function(i,item){
			var option = $("<option>").html(item.TDMC).val(item.TDID);
			$TDID.append(option);
		})*/
        $("[name=TDIDS]").createOptions(tdxxArr,{textField : "TDMC" , valueField : "TDID"});
	}
    	
	/** 完成服务/查看详细  */
    function doedTask(taskData,type){
		var title = '服务详细';
		var area = ["900px", "310px"];
		if(StringUtils.isEmpty(taskData.SJFWSJ)){
			title = '完成服务'
			area = ["900px", "350px"];
		}
    	StoreCache.setCache("taskData", taskData);
    	if(type==1){
    		StoreCache.setCache("onlyQuery",true);
    	}
    	parent.layer.open({
			  type: 2,
			  area: area,
			  content: contextRoot+"wdqyhz/wcrw.html",
			  scrollbar: false,
			  title:title,
			  end: function(){
				  var refresh = StoreCache.removeCache("refresh");
				  if(refresh){
					  $("#wdFwxTable").datagrid("reload");
                      $("#allFwxTable").datagrid('reload');
				  }
			  }
		});
    }
	
   	
   	/** 我的服务项查询  */
   	function wdFwxQueryHandler(){
   		$("#wdFwxTable").datagrid({"url": contextRoot + "wdqyhz/queryYfpfwxByPage.service"});
   	}
   	
   	/** 所有服务项查询  */
   	function allFwxQueryHandler(){
   		$("#allFwxTable").datagrid('reload');
   	}
   	
   	var initTableMethod = {
   			wdFwxTable: function(){
   				$("#wdFwxTable").datagrid({
   					idField : "FPFWID",
   					striped : true,
   					clickToSelect: true,
   					fitColumns: true,
   					fit:true,
   					scrollbarSize:0,
   					singleSelect:true,
   					columns : [[
   							{field : "XM",title : "签约居民",width:40, align:'center'},
   							{field : "FWBMC",title : "签约服务包",width:60, align:'center',formatter:function(value){
                                if(StringUtils.isEmpty(value)){
                                    return '<span class="fdztCss">医保服务项</span>';
                                }else{
                                    return '<span title="'+ value +'">'+ value + '</span>'
                                }
                            }},
   							{field : "FWDX",title : "服务对象",width:40, align:'center'},
   							{field : "FWMC",title : "服务项",width:60, align:'center',formatter:function(value){
                                return '<span title="'+ value +'">'+ value + '</span>'
                            }},
   							{field : "FWNR",title : "服务项内容",width:120, align:'center',formatter:function(value){
   					    		return '<span title="'+ value +'">'+ value + '</span>'
							}},
   							{field : "QYTD",title : "签约团队",width:60, align:'center',formatter:function(value){
                                return '<span title="'+ value +'">'+ value + '</span>'
                            }},
   							{field : "YQFWSJ",title : "预期服务时间",width:60, align:'center',formatter: function(value){
								if(!StringUtils.isEmpty(value)){
									return value.substring(0,10);
								}
							}},
   							{field : "SJFWSJ",title : "实际服务时间",width:60, align:'center',formatter: function(value){
								if(!StringUtils.isEmpty(value)){
									return value.substring(0,10);
								}
							}},
   							{field : "cz",title : "操作",width:60,align:'center',
								formatter:function(value,row,index){
									var sjfwsj = row.SJFWSJ;
									row = JSON.stringify(row).replace(/"/g, '&quot;');
									if(StringUtils.isEmpty(sjfwsj)){
										return '<span onclick="doedTask(' + row + ')">完成服务</span>';
									}else{
										return '<span class="spanBtn" onclick="doedTask(' + row + ')">详细</span>';
									}
								},
                                styler: function(value,row,index){
                                    if (row.FWZT == 0){
                                        return "font-weight:bold;cursor:pointer";
                                    }else{
                                        return "font-weight:bold;cursor:pointer;color:blue";
                                    }
                                }
   							}
   					]],
   					pagination : true,
   					pageList: [10, 20, 50, 100, 200],
   					method : "post",
   					onBeforeLoad : function(params) {
   						$("#USERID").val(parent.userInfo.USERID);
   						getContainerDataByClassName('wdFwxConditionBox','condition',params);//查询条件
   					},
   					rowStyler: function(index,row){
                        if (row.FWZT == 0){
                            return "color:red";
                        }
                    }
   				});
   			},
   			
   			allFwxTable: function(){
   				$("#allFwxTable").datagrid({
   					idField : "FPFWID",
   					striped : true,
   					clickToSelect: true,
   					fitColumns: true,
   					fit:true,
   					scrollbarSize:0,
   					singleSelect:true,
   					columns : [[
   							{field : "XM",title : "签约居民",width:40, align:'center'},
   							{field : "FWBMC",title : "签约服务包",width:60, align:'center',formatter:function(value){
                                if(StringUtils.isEmpty(value)){
                                    return '<span class="fdztCss">医保服务项</span>';
                                }else{
                                    return '<span title="'+ value +'">'+ value + '</span>'
                                }
                            }},
   							{field : "FWDX",title : "服务对象",width:40, align:'center'},
   							{field : "FWMC",title : "服务项",width:60, align:'center',formatter:function(value){
   								return '<span title="'+value+'">'+value+'</span>';
   							}},
   							{field : "FWNR",title : "服务项内容",width:120, align:'center',formatter:function(value){
                                return '<span title="'+ value +'">'+ value + '</span>'
                            }},
   							{field : "QYTD",title : "签约团队",width:60, align:'center',formatter:function(value){
                                return '<span title="'+ value +'">'+ value + '</span>'
                            }},
   							{field : "YQFWSJ",title : "预期服务时间",width:60, align:'center',formatter: function(value){
								if(!StringUtils.isEmpty(value)){
									return value.substring(0,10);
								}
							}},
   							{field : "SJFWSJ",title : "实际服务时间",width:60, align:'center',formatter: function(value){
								if(!StringUtils.isEmpty(value)){
									return value.substring(0,10);
								}
							}},
   							{field : "FWRY",title : "服务人员",width:60, align:'center'},
   							{field : "cz",title : "操作",width:60,align:'center',
								formatter:function(value,row,index){
									var rowCopy = JSON.stringify(row).replace(/"/g, '&quot;');
									if(StringUtils.isEmpty(row.SJFWSJ) && (parent.userInfo.USERID==row.USERID || row.TDJS == 3)){
										return '<span onclick="doedTask(' + rowCopy + ')">完成服务</span>';
									}else{
										return '<span onclick="doedTask('+ rowCopy +',1)">详细</span>';
									}
								},
                                styler: function(value,row,index){
                                    if (row.FWZT == 0){
                                        return "font-weight:bold;cursor:pointer";
                                    }else{
                                        return "font-weight:bold;cursor:pointer;color:blue";
									}
                                }
                            }
   					]],
   					pagination : true,
   					pageList: [10, 20, 50, 100, 200],
   					method : "post",
   					url: contextRoot + "wdqyhz/queryYfpfwxByPage.service",
   					onBeforeLoad : function(params) {
   						getContainerDataByClassName('allFwxConditionBox','condition',params);//查询条件
   						if(StringUtils.isEmpty(params.TDIDS)){
   							var tdidArr = [];
   							$("#allFwxTDIDS option").each(function(){
   								var val = $(this).val();
   								if(!StringUtils.isEmpty(val)){
   									tdidArr.push(val);
   								}
   							})
   							params.TDIDS = tdidArr.join();
   						}
   					},
   					rowStyler: function(index,row){
                        if (row.FWZT == 0){
                            return "color:red !important";
                        }
                    }
                });
   			}
   	}
   	
   	
   	/** 导出我的服务项  */
   	function downloadWdfw(){
   		$("#wdfwForm").submit();
   	}
   	
   	/** 导出所有服务项  */
   	function downloadAllfw(){
   		var TDIDS = $("#allFwxTDIDS").val();
   		if(StringUtils.isEmpty(TDIDS)){
			var tdidArr = [];
			$("#allFwxTDIDS option").each(function(){
				var val = $(this).val();
				if(!StringUtils.isEmpty(val)){
					tdidArr.push(val);
				}
			})
			$("#downTDIDS").val(tdidArr.join());
		}
   		$("#allfwForm").submit();
   	}
</script>

</head>

<body style="visibility:hidden">
	<div id="tabs" class="easyui-tabs" fit="true" border="false">
    	<div title="我的服务">
			<div class="easyui-layout" fit="true" border="false">
				<div region="north" style="overflow:hidden;padding:15px 0px;background:#f9f9f9" border="false">
					<form action="downloadFwjl.service" method="post" enctype="multipart/form-data" id="wdfwForm">
						<table class="form-table" id="wdFwxConditionBox">
							<tr>
								<td class="td-text">签约居民：</td>
								<td class="td-content">
									<input type="hidden" name="USERID" id="USERID" class="condition"/>
									<input name="XM" class="form-control condition"  style="width: 100%;">
								</td>
								<td class="td-text">签约团队：</td>
								<td class="td-content">
									<select name="TDIDS" class="form-control condition" style="width: 100%;">
										<option value="">请选择</option>
									</select>
								</td>
								<td class="td-text" style="width:120px;">预期服务时间：</td>
								<td class="td-content">
									<div style="display: inline;">
										<input name="YQFWSJ" onclick="laydate()" class="form-control laydate-icon condition" />
									</div>
								</td>
								<td class="td-text" style="width:170px;text-align:left;text-align:center;">
									<button id="btnQuery" class="btn btn-info" type="button" onclick="wdFwxQueryHandler()">查询</button>
									<button class="btn btn-info" type="button" onclick="downloadWdfw()">导出</button>
								</td>
							</tr>
						</table>
					</form>
				</div>
				<div region="center" border="false">
					<table id="wdFwxTable" border="false"></table>
				</div>
			</div>
		</div>
	
		<div title="所有服务">
			<div class="easyui-layout" fit="true" border="false">
				<div region="north" style="overflow:hidden;padding:15px 0px;background:#f9f9f9" border="false">
					<form action="downloadFwjl.service" method="post" enctype="multipart/form-data" id="allfwForm" >
						<table class="form-table" id="allFwxConditionBox">
							<tr>
								<td class="td-text">签约居民：</td>
								<td class="td-content">
									<input type="hidden" name="downTDIDS" id="downTDIDS"/>
									<input name="XM" class="form-control condition"  style="width: 100%;">
								</td>
								<td class="td-text">签约团队：</td>
								<td class="td-content">
									<select id="allFwxTDIDS" name="TDIDS" class="form-control condition" style="width: 100%;">
										<option value="">请选择</option>
									</select>
								</td>
								<td class="td-text" style="width:120px;">预期服务时间：</td>
								<td class="td-content">
									<div style="display: inline;">
										<input name="YQFWSJ" onclick="laydate()" class="form-control laydate-icon condition" />
									</div>
								</td>
								<td class="td-text" style="width:170px;text-align:left;text-align:center;">
									<button id="btnQuery2" class="btn btn-info" type="button" onclick="allFwxQueryHandler()">查询</button>
									<button class="btn btn-info" type="button" onclick="downloadAllfw()">导出</button>
								</td>
							</tr>
						</table>
					</form>
				</div>
				<div region="center" border="false">
					<table id="allFwxTable" border="false"></table>
				</div>
			</div>
		</div>
	</div>
	
</body>

</html>
